package esiag.pds.servers;


import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.io.Serializable;
import java.net.*;

import esiag.pds.PoolThread.RejectedExecutionHandlerImpl;
import esiag.pds.PoolThread.ReplicationCallable;
import esiag.pds.beans.Information;
import esiag.pds.contextManagement.Context;
import esiag.pds.contextManagement.ContextManager;
import esiag.pds.interfaces.IgetContext;



public class RMIServer{
	
	  int port;
	  Registry registry; 
		    
	  public RMIServer(int port) throws RemoteException{
		  this.port=port;
		  try{
			  registry = LocateRegistry.createRegistry(port);
		  }
		  catch(RemoteException e){
			  System.out.println("remote exception"+ e);
		  }
	  }
	  
	  public void rebind(ContextManager cm){
		  try {
			  
			registry.rebind("Context",cm);
			
		} catch (AccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	  }

	/* 
	static void testPool() throws RemoteException{
		ContextManager cm=new ContextManager();
		
		RejectedExecutionHandlerImpl rehi;
		ThreadFactory threadFactory;
		ThreadPoolExecutor executorPool;
				
		rehi=new RejectedExecutionHandlerImpl();
		threadFactory = Executors.defaultThreadFactory();
		executorPool = new ThreadPoolExecutor(2, 4, 2,
				TimeUnit.SECONDS, 
				new ArrayBlockingQueue<Runnable>(2),
				threadFactory, rehi);
		
		Future<Context> future=executorPool.submit (new ReplicationCallable(cm));
			try {
				System.out.println(future.get().toString());
			} catch (Exception e) {
				e.printStackTrace();
			} 
	}
	*/

}